-
Notifications
You must be signed in to change notification settings - Fork 975
enable scrolling inside of iframes #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable scrolling inside of iframes #919
Conversation
🦋 Changeset detectedLatest commit: 972a190 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
0d329a8
to
ba001ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR fixes a critical limitation in Stagehand where scrolling actions could not be performed inside iframes. The changes address two specific technical issues:
-
Execution Context Problem: The original implementation used
page.evaluate
for all scrolling operations, which meant scrolling could only occur at the page level and not within iframe contexts. The fix refactors three key scrolling functions (scrollToNextChunk
,scrollToPreviousChunk
, andscrollElementToPercentage
) inactHandlerUtils.ts
to uselocator.evaluate
instead, leveraging the locator's inherent iframe-awareness. -
Same Process Iframe (SPIF) Context Resolution: For SPIFs that share the same Chrome DevTools Protocol (CDP) session as the root document, the code wasn't properly specifying execution contexts when resolving XPaths for scrollable elements. This caused
resolveObjectIdForXPath
to only search in the root document context, missing elements inside SPIFs. The solution introduces a newgetFrameExecutionContextId
function inutils.ts
that creates isolated worlds for SPIFs, ensuring XPath evaluation happens in the correct execution context.
The changes integrate seamlessly with Stagehand's existing iframe handling architecture by building upon Playwright's locator system rather than introducing new iframe traversal logic. A new evaluation test iframe_scroll
has been added to validate the functionality, testing that the act
method can successfully scroll within a same-process iframe and verify the scroll position.
Confidence score: 3/5
- This PR addresses real functionality gaps but has several implementation concerns that could cause issues
- Score reflects solid architectural improvements but potential reliability issues in the test implementation and some complex CDP context handling
- Pay close attention to
evals/tasks/iframe_scroll.ts
for brittle frame access patterns andlib/a11y/utils.ts
for CDP context management complexity
4 files reviewed, 3 comments
why
this PR addresses two issues, both related to scrolling inside iframes:
.evaluate
inside frames:performPlaywrightMethod
callspage.evaluate
locator.evaluate
resolveObjectIdForXPath
, this executes in either the page level execution context, or, for OOPIFs (out of process iframes), the frame level execution contextresolveObjectIdForXPath
only searches in the root document execution context, and can't see anything inside of the SPIFwhat changed
scrollToNextChunk
,scrollToPreviousChunk
,scrollElementToPercentage
all uselocator.evaluate
instead ofpage.evaluate
which enables scrolling inside (and outside) of iframesgetFrameExecutionContextId
which creates an isolated world & returns a SPIF scoped execution contextresolveObjectIdForXPath
which guarantees that we are searching for scrollable elements in the correct execution contexttest plan
act
evalstargeted_extract
evalsobserve
evalsextract
evals